package com.gx.cn.hospitalmanage.HospitalManage;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.gx.cn.hospitalmanage.MainActivity;
import com.gx.cn.hospitalmanage.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by JCQ on 2017/10/6.
 */

public class HospitalRegistraActivity extends AppCompatActivity {

   public HospitalRegistraActivity()
   {

   }


    //定义图标下方的名称数组
    private String[] name = {
            "住院历史",
            "确认住院",
            "新患者",
    };


    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hospital_registration);


        List<String>    data_list =new ArrayList<String>();
        data_list.add("门诊转入");
        data_list.add("急诊转入");
        data_list.add("其他科室转入");
        data_list.add("医院转入");

        ArrayAdapter<String>  arr_adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,data_list);
        arr_adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);

        Spinner  spinner=(Spinner) findViewById(R.id.spinner1);
        spinner.setAdapter(arr_adapter);


        // 九宫格按钮
        GridView gridView=(GridView)findViewById(R.id.gridview);//初始化

        //生成动态数组，并且转入数据
        ArrayList<HashMap<String ,Object>> listItemArrayList=new ArrayList<HashMap<String,Object>>();
        for(int i=0; i<name.length; i++){
            HashMap<String, Object> map=new HashMap<String,Object>();

            map.put("itemText", name[i]);
            listItemArrayList.add(map);
        }
        //生成适配器的ImageItem 与动态数组的元素相对应
        SimpleAdapter saImageItems = new SimpleAdapter(this,
                listItemArrayList,//数据来源
                R.layout.activity_hospital_registration_btnstyle,//item的XML

                //动态数组与ImageItem对应的子项
                new String[]{ "itemText"},

                //ImageItem的XML文件里面的一个ImageView,TextView ID
                new int[]{ R.id.txt_shoukuan});
        //添加并且显示
        gridView.setAdapter(saImageItems);
        //添加消息处理
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                               //显示消息
                Toast.makeText(HospitalRegistraActivity.this,name[position],Toast.LENGTH_LONG).show();

                int index=position+1;//id是从0开始的，所以需要+1
                if(index==1){
                  Toast.makeText(HospitalRegistraActivity.this,"住院历史为空",Toast.LENGTH_LONG).show();
                }

                if(index==2){

                }

            }
        });


    }


}
